<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<c:set var="ctx" value="${pageContext.request.contextPath }"/>
<jsp:include page="../inc.jsp"></jsp:include>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
	<style type="text/css">
		div#mftb ul{
			list-style: none;
			margin-top: 5px;
			margin-left: 0px;
		}
		div#mftb ul li{
			list-style: none;
			float: left;
			width: 60px;
		}
	</style>
</head>
<body class="easyui-layout">
	<script type="text/javascript">
		var mfdg;
		var urlMF = '${ctx}/mfc/find.coc';
		$(function() {
			
			$('#natureTb').datagrid({//获取会费性质数据
				url:'${ctx}/mfnc/find.coc'
			});
			
			mfdg = $('#mfTable').datagrid({
				url:urlMF,
				fit:true,
				singleSelect:true,//单选
				rownumbers:true,//行序列
				pagination:true,//底部分页工具栏
				columns:[[
					{field:'ck',checkbox:true,width:50},
					{field:'id',title:'费用编号',width:100,align:'center',hidden:true},
					{field:'name',title:'费用名称',width:100,align:'center'},
					{field:'shouldPayMF',title:'应缴费用',width:100,align:'center'},
					{field:'dueDate',title:'到期时间',width:150,align:'center',sortable:true},
					{field:'stateDate',title:'时间状态',width:100,align:'center',
						formatter:function(v,r,i){
							if(r.dueDate!='' && r.dueDate.length>0){
								var dueDate = StringTurnDate(r.dueDate);
								var today = new Date();
								if(dueDate - today <= 0){
									return "<a >已过期</a>";
								}else{
									var day = (dueDate.getTime()-today.getTime())/(24*3600*1000);
									return "最后<a style='color:red'>"+day+"</a>天";
								}
							}
						}
					},
					{field:'nature',title:'性质',width:100,align:'center',
						formatter:function(v,r,i){
							var ns = $('#natureTb').datagrid('getRows');
							for (var i = 0; i < ns.length; i++) {
								if(v == ns[i].id){
									return ns[i].name;
								}
							}
						}
					},
					{field:'at',title:'操作',width:100,align:'center',
						formatter:function(v,r,i){
							v = '';
							v += '<a onclick="editData('+i+')" href="#" style="color:blue;text-decoration:none">编辑<a/>';
							v += '&nbsp;|&nbsp;';
							v += '<a onclick="delData('+i+')" href="#" style="color:red;text-decoration:none">删除<a/>';
							return v;
						},
						styler:function(v,r,i){
							return 'background-color:#d4d4d4';
						}
					}
				]]
			});
			//刷新分页
			//setTimeout(function(){dg.datagrid({loadFilter:pagerFilter}).datagrid('loadData')},10);
			
		});
		
		function StringTurnDate(str){
			var date = new Date();
			str = str.split("-");
			y = parseInt(str[0]);
			m = parseInt(str[1]);
			d = parseInt(str[2]);
			date.setFullYear(y,m-1,d);
			return date;
		}
		
		function addMF(){
			openDiglog('新增的窗口','');
		}
		function editMF(index){
			mfdg.datagrid('selectRow',index);
			var row = mfdg.datagrid('getSelected');
			openDiglog('编辑的窗口',row);
		}
		function openDiglog(title,row){
			var vals = '';
			var url = '${ctx}/mfc/insertNoFile.coc';
			if(row!=''){
				var vals = '?vals='+JSON.stringify(row);
				var url = '${ctx}/mfc/edit.coc';
			}	
			parent.$.modalDialog({
				title:title,
				href:'${ctx}/mfc/aoe.coc'+vals,
				modal:true,
				width:400,
				height:500,
				buttons:[{
					text:'保存',
					iconCls:'icon-save',
					plain:true,
					handler:function(){
						var f = parent.$.modalDialog.handler.find('#mfDataForm');
						if(f.form('validate')){
							var option = {
								type:'post',
								url:url,
								dataType:'json',
								success:function(r){
									alert(r.msg);
									if(r.is){
										parent.$.modalDialog.handler.dialog('close');
										mfdg.datagrid('reload');//重新加载数据
									}
								}
								
							};
							f.ajaxSubmit(option);//数据提交
						}
					}
				},{
					text:'取消',
					iconCls:'icon-cancel',
					plain:true,
					handler:function(){
						parent.$.modalDialog.handler.dialog('close');
					}
				}]
			});
		}
	</script>
	
    <div data-options="region:'west',title:'会费管理' " 
    style="width:720px;">
    	<table class="searchTb" 
    	style="height: 30px;padding:10px;min-width: 700px;">
    		<tr>
    			<td></td>
    			<td></td>
    		</tr>
    	</table>
    	
    	<div id="mftb" style="height: 36px;
	    border:1px solid #d4d4d4;margin: 0px 10px;">
	    	<ul style="list-style: none;
				margin-top: 5px;
				margin-left: 0px;">
	    		<li>
	    			<a onclick="addMF()" class="easyui-linkbutton" plain=true iconCls="icon-eadd">新增</a>
	    		</li>
	    		<li style="width: 150px;">
	    			<a onclick="batchDel()" class="easyui-linkbutton" plain=true iconCls="icon-delete">批量删除(ctrl多选)</a>
	    		</li>
	    		<li>
	    			<a onclick="sunData()" class="easyui-linkbutton" plain=true iconCls="icon-pie">统计</a>
	    		</li>
	    		<li>
	    			<a onclick="redoData()" class="easyui-linkbutton" plain=true iconCls="icon-redo">导出</a>
	    		</li>
	    		<li style="float:right;width: auto;
	    			background: #d4d4d4;height: 31px;margin-top: -5px;padding-top: 5px;">
	    			<a id="cancelRow" class="easyui-linkbutton" plain=true iconCls="icon-del">取消选择</a>
	    		</li>
	    	</ul>
	    </div>
	    
	    <table id="natureTb" style="display:none;height: 0px"></table>
    	<table id="mfTable"></table>
    </div>
    
    <div data-options="region:'center',title:'会员'" 
    style="padding:5px;background:#eee;" href="${ctx }/mfc/memberMF.coc"></div>   
	
</body>
</html>